package net.xumf.web.controller.common;

import io.swagger.annotations.ApiOperation;
import net.xumf.support.annotation.UserActionLog;
import net.xumf.support.consts.Constants;
import net.xumf.support.model.ResponseResult;
import net.xumf.support.model.dto.PageDTO;
import net.xumf.support.model.vo.PageVO;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 基础方法controller
 *
 * @param <T> 用于拓展分页对象
 * @param <P>  pojo
 * @param <ID> 对应表中的主键类型
 */
public interface BaseController<T extends PageDTO, P, ID> {

    /**
     * 获取数据
     *
     * @param id id
     * @return {@link ResponseResult}
     */
    @ApiOperation(value = "通过id获取数据")
    @GetMapping(Constants.UrlPath.ID_PATH_ACTION)
    ResponseResult get(@PathVariable ID id);

    /**
     * 分页获取列表
     *
     * @param pageDTO {@link PageDTO}
     * @return {@link PageVO}
     */
    @ApiOperation(value = "分页获取列表")
    @GetMapping(Constants.UrlPath.GET_ALL_PAGE)
    PageVO getByPage(T pageDTO);

    /**
     * 获取所有列表
     *
     * @return {@link ResponseResult}
     */
    @ApiOperation(value = "获取所有列表")
    @GetMapping
    ResponseResult getAll();

    /**
     * 增加数据
     *
     * @param p pojo对象
     * @return {@link ResponseResult}
     */
    @ApiOperation(value = "添加数据")
    @PostMapping
    ResponseResult add(@RequestBody P p);

    /**
     * 更新数据
     *
     * @param p pojo对象
     * @return {@link ResponseResult}
     */
    @ApiOperation(value = "修改数据")
    @PutMapping(Constants.UrlPath.ID_PATH_ACTION)
    ResponseResult edit(@PathVariable("id") ID id, @RequestBody P p);

    /**
     * 删除数据
     *
     * @param id pojoId
     * @return {@link ResponseResult}
     */
    @ApiOperation(value = "删除数据")
    @DeleteMapping(Constants.UrlPath.ID_PATH_ACTION)
    ResponseResult del(@PathVariable ID id);

    /**
     * 删除数据
     *
     * @return {@link ResponseResult}
     */
    @ApiOperation(value = "删除所有数据")
    @DeleteMapping
    ResponseResult delAll();

}
